package com.logicfishsoftware.wolfgo.meta.impl;

import org.openrdf.repository.RepositoryException;

import com.logicfishsoftware.wolfgo.api.VirtualFileSystem;
import com.logicfishsoftware.wolfgo.api.VirtualFileSystemConnection;
import com.logicfishsoftware.wolfgo.api.VirtualFileSystemException;
import com.logicfishsoftware.wolfgo.meta.SemanticFileSystemProvider.SemanticFileSystemHandler;

public final class SemanticFileSystem implements VirtualFileSystem {

	private SemanticFileSystemHandler handler;

	protected SemanticFileSystem(SemanticFileSystemHandler handler) throws VirtualFileSystemException {
		this.handler = handler;
	}

	@Override
	public VirtualFileSystemConnection connect() throws VirtualFileSystemException {
		try {
			return new SemanticFileSystemConnection(handler.getConnection(this),handler);
		} catch (RepositoryException e) {
			throw new SemanticFileSystemException(e);
		}
	}
	
	@Override
	public void shutdown() {
		handler.shutdown(this);
	}

	public static SemanticFileSystem createFileSystem(SemanticFileSystemHandler handler) throws VirtualFileSystemException {
		SemanticFileSystem fileSystem = new SemanticFileSystem(handler);
		return fileSystem;
	}
}